(** Module GenTex
 *
 *  Author: Jk
 *)

(*open Misc
open Types
open Printf

let translate_name = encodeName (function "_"->"-"| c->c) 
	 
let generate rule= 
    let rec gen_body rule = match rule.tree with
       AltBlock   l     -> "\\bgrp\\rbr\\phantom{\\ralt}" ^ String.concat "\\rbr\n\t\\ralt" (List.map gen_body l) ^ "\\egrp"
     | SeqBlock  (s, _) -> String.concat "\\rb" (List.map (fun x -> gen_body x) s)
     | TokenRef   n     -> sprintf "\\term{%s}" (translate_name n)
     | RuleRef   (r,p)  -> sprintf "\\nt{%s}" (translate_name r)
     | RawString  s     -> sprintf "\\term{'%s'}" (String.escaped s)
     | Iterated  (r,q)  ->  
              (fun o x -> match o with 
               | MOpt  -> "\\bopt" ^ x ^ "\\eopt" 
               | MSome -> "\\bgrp" ^ x ^ "\\egrp\\niter"
               | MAny  -> "\\bgrp" ^ x ^ "\\egrp\\iter"
              ) q (gen_body r)
     | Predicate _ -> ""
    in sprintf "\\newcommand{\\%s}{\\grule{%s}{%s\\rend}}" (translate_name rule.name) (translate_name rule.name) (gen_body rule.body)

let generate_grammar g = print_endline ("\\makehypletter\n" ^ String.concat "\n\n" (List.map generate g.rules) ^ "\n\n\\makehypother" )

let generator conf g = generate_grammar g
*)